Description:
C# does not have key parameters - only positioned ones, so it is not difficult to make a mistake and misplace actual parameters in a method call. If the types of such parameters are compatible, the compiler will not be able to detect this problem.
MAP attempts to detect such errors, based on the assumption that
the passed parameter value is usually a variable with a meaningful name.
For example, if we have the
draw(int line, int column, char ch)
method then most likely, this method will be called like this:
for (int line = 0; line < nLines; line++) {
for (int column = 0; column < nColumns; column++) {
draw(line, column, ch);
}
}
If it is instead called like this: draw(column, line, ch), it
is an indication that the programmer swapped the method arguments.
However, this approach does not work if the method is called like this:
draw(x, y, ch). To deal with this case, MAP tries to match
the names of actual parameters not only with the names of formal parameters, but
also with the names of the actual parameters in other invocations of this method.
If in most cases the methods above are invoked as draw(y, x, ch),
but in some places as draw(x, y, ch), then it is most likely an error.
Incorrect:
class Display {
void draw(int line, int column, char ch) { ... }
}
...
for (int line = 0; line < nLines; line++) {
for (int column = 0; column < nColumns; column++) {
draw(column, line, ch);
}
}
...
draw(x, y, '!');
draw(y, x, '?');
Correct:
for (int line = 0; line < nLines; line++) {
for (int column = 0; column < nColumns; column++) {
draw(line, column, ch);
}
}
...
draw(x, y, '!');
draw(x, y, '?');